/**
 * @a https://leetcode.cn/problems/kth-largest-element-in-a-stream/
 */

#include <../common.h>
class KthLargest {
public:
    KthLargest(int k, vector<int>& nums) 
    :_k(k)
    {
        for(auto num : nums){
            _pq.push(num);
            if(_pq.size() > _k) _pq.pop();
        }
    }
    
    int add(int val) {
        _pq.push(val);
        if(_pq.size() > _k) _pq.pop();
        return _pq.top();
    }
private:
    priority_queue<int,vector<int>, greater<int>> _pq;
    int _k;
};

/**
 * Your KthLargest object will be instantiated and called as such:
 * KthLargest* obj = new KthLargest(k, nums);
 * int param_1 = obj->add(val);
 */